#!/bin/bash
cd ${0%/*} || exit 1    # run from this directory

if [ "$WM_PROJECT_DIR" == "" ] ; then
   source etc/bashrc
   echo "$WM_PROJECT_DIR"
fi

if [ "$PWD" != "$WM_PROJECT_DIR" ] ; then
    echo "Error: Current directory is not \$WM_PROJECT_DIR"
    echo "    The environment variable are not consistent with the installation."
    echo "    Check the OpenFOAM entries in your dot-files and (un)source them."
    exit 1
fi



# build OpenFOAM libraries and applications

(cd wmake/src && make)

src/Allwmake

if [ -f applications/Allwmake ] ; then 
  applications/Allwmake
fi

if [ -f cfMesh/Allwmake ] ; then 
  echo "(cd cfMesh && ./Allwmake)"
  (cd cfMesh && ./Allwmake)
fi

if [ "$1" = doc ] ; then
    doc/Allwmake
fi
